﻿using System;
using CommonDomain;

namespace Sponsorship.Domain.SponsorshipTypes
{
    /// <summary>
    /// Represents a sponsorship type in the Sponsorship domain. A <see cref="Sponsorship"/> always holds a reference to a <see cref="SponsorshipType"/>.
    /// </summary>
    public class SponsorshipType : RelaxedAggregateBase
    {
        public SponsorshipType (Guid sponsorshipTypeId, string name, decimal amount, Period period, string comment)
            : this (sponsorshipTypeId, null)
        {
            if (sponsorshipTypeId == Guid.Empty)
                throw new ArgumentException ("Id must not be empty.", "id");

            RaiseEvent (new SponsorshipTypeEntered (sponsorshipTypeId, name, amount, period, comment));
        }

        // Infrastructure constructor used by AggregateFactory
        private SponsorshipType (Guid id, IMemento snapshot)
        {
            if (snapshot != null)
                throw new NotSupportedException ("This class does not support snapshots.");
            Id = id;
        }

        public void Delete()
        {
            RaiseEvent (new SponsorshipTypeDeleted (Id));
        }

        internal void Change (string name, decimal amount, Period period, string comment)
        {
            RaiseEvent (new SponsorshipTypeChanged (Id, name, amount, period, comment));
        }

        protected override IMemento GetSnapshot()
        {
            throw new NotSupportedException ("This class does not support snapshots.");
        }
    }
}